package com.cuijun.spring5.testdemo;

import com.cuijun.spring5.Bean.Orders;
import com.cuijun.spring5.autowire.Emp;
import com.cuijun.spring5.collecttiontype.Book;
import com.cuijun.spring5.collecttiontype.Course;
import com.cuijun.spring5.collecttiontype.Stu;
import com.cuijun.spring5.collecttiontype.Stu2;
import com.cuijun.spring5.factorybean.MyBean;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSpring5Demo1 {

    @Test
    public void testCollection(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean1.xml");
        Stu stu=context.getBean("stu",Stu.class);
        stu.test();
    }

    @Test
    public void testCollection2(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean2.xml");
        Stu2 stu2=context.getBean("stu",Stu2.class);
        stu2.test();
    }

    @Test
    public void testCollection3(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean3.xml");
        Book book=context.getBean("book", Book.class);
        Book book2=context.getBean("book", Book.class);
        //book.test();
        System.out.println(book);
        System.out.println(book2);
    }

    @Test
    public void testCollection4(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean4.xml");
        Course course=context.getBean("myBean", Course.class);
        System.out.println(course);
    }

    @Test
    public void testCollection5(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean5.xml");
        Orders orders=context.getBean("orders", Orders.class);
        System.out.println("第四步 获取创建bean实例对象");
        System.out.println(orders);

        //手动让bean实例销毁
        ((ClassPathXmlApplicationContext)context).close();
    }
    @Test
    public void testCollection6(){
        ApplicationContext context =
                new ClassPathXmlApplicationContext("bean6.xml");
        Emp emp=context.getBean("emp", Emp.class);
        System.out.println(emp);
    }
}
